﻿using LitJson;
using OestsCommon;
using OestsCommon.Model;
using OestsCommon.TcpNet;
using OestsServer.Managers;
using OestsServer.Net;

namespace OestsServer.Handlers
{
    /// <summary>
    /// 设置岗位
    /// </summary>
    public class SetPostHandler : HandlerBase
    {
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.SetPost;
            }
        }
        public override void Execute(ClientChannel client, Request packet)
        {
		//	Struct3<int, int, int> data = JsonMapper.ToObject<Struct3<int, int, int>>(packet.DataStr);

		//	if (data != null)
		//	{
		//		//协议解析
		//		int roomId = data.Value1;
		//		int studentId = data.Value2;
		//		int postId = data.Value3;

		//		foreach (var r in RoomManager.Instance.RoomList)
		//		{
		//			if (r.RoomId == roomId)
		//			{
		//				//如果该用户已经扮演了岗位，清除扮演信息
		//				if (r.DicPostIdStudentId.ContainsValue(studentId))
		//				{
		//					foreach (var item in r.DicPostIdStudentId)
		//					{
		//						if (item.Value == studentId)
		//						{
		//							Response cancelPostPacket = new Response(PKey);
		//							cancelPostPacket.ResponseSubCode = SubCode.SetPost;
		//							cancelPostPacket.ReturnCode = ReturnCode.Success;
		//							cancelPostPacket.DataObject = new Struct3<int, int, int>() { Value1 = roomId, Value2 = studentId, Value3 = 0 };
		//							r.DicPostIdStudentId[item.Key] = 0;
		//							BroadcastInRoom(r, cancelPostPacket);
		//							break;
		//						}
		//					}
		//				}

		//				if (r.DicPostIdStudentId.ContainsKey(postId.ToString()))
		//				{
		//					//表示该岗位已经有人扮演了，新的学员将要代替旧的学员扮演该岗位,旧的学员设置的岗位清除，广播出去
		//					if (r.DicPostIdStudentId[postId.ToString()] > 0 && r.DicPostIdStudentId[postId.ToString()] != studentId)
		//					{
		//						Response cancelPostPacket = new Response();
		//						cancelPostPacket.ResponseCode = PacketKey.SetPost;
		//						cancelPostPacket.ResponseSubCode = SubCode.SetPost;
		//						cancelPostPacket.ReturnCode = ReturnCode.Success;
		//						cancelPostPacket.DataObject = new Struct3<int, int, int>() { Value1 = roomId, Value2 = r.DicPostIdStudentId[postId.ToString()], Value3 = 0 };
		//						BroadcastInRoom(r, cancelPostPacket);
		//					}
							
		//					//设置岗位新的扮演者
		//					r.DicPostIdStudentId[postId.ToString()] = studentId;
		//				}
		//				ResponsePacket.DataObject = data;
		//				//房间广播
		//				BroadcastInRoom(r, ResponsePacket);
		//				break;
		//			}
		//		}
		//	}
		}
    }

}
